from PyQt5.QtCore import pyqtSlot, pyqtSignal
from PyQt5.QtWidgets import QWidget, QCheckBox, QLabel, QVBoxLayout, QListWidget, QHBoxLayout, QPushButton


class Conveyor(QWidget):
    def __init__(self):
        super().__init__()

        layout = QHBoxLayout()
        self.cb1 = QCheckBox()
        self.cb2 = QCheckBox()
        self.l1 = QLabel("红外")
        self.l2 = QLabel("电机输出")
        layout.addWidget(self.cb1)
        layout.addWidget(self.cb2)
        layout.addWidget(self.l1)
        layout.addWidget(self.l2)

        self.setLayout(layout)


class ConveyorWidget(QWidget):
    sig_state = pyqtSignal(tuple)

    def __init__(self, count):
        super().__init__()

        self.li = []
        self.layout = QVBoxLayout()
        for _ in range(count):
            con = Conveyor()
            self.li.append(con)
            self.layout.addWidget(con)

        # button = QPushButton("b")
        # button.pressed.connect(self.press)
        self.sig_state.connect(self.update_widget)
        # self.layout.addWidget(button)

        self.setLayout(self.layout)
    #
    # def press(self):
    #     print("press")
    #     self.sig_state.emit((1, "abc"))

    @pyqtSlot(tuple)
    def update_widget(self, data):
        # print(data[0])
        con = self.li[data[0]]
        # print(con)
        con.l1.setText(str(data[1]))
        con.l2.setText(str(data[2]))
